package calorie.com.calorie.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.SPUtils;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.BaseRequest;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;



public class ModifyPhoneContact {
    public static class ModifyPhoneContactPresent extends BasePresent<IModifyPhone> {
        public void sendCode(Context context) {//发送验证码
            ApiService service = ServiceGenerator.createService(ApiService.class);
            BaseRequest request = new BaseRequest();
            int userId = SPUtils.getInt(Constant.USER_ID, 0, context);
            request.put("userId", userId);
            String phone = SPUtils.getString(Constant.PHONE, "", context);
            request.put("phone", phone);
            request.put("type", "5");
            service.modifyPhoneSendCode(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getYZM(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }

        public void checkInfo(Context context, String yzm, String loginPassword) {//检查信息
            ApiService service = ServiceGenerator.createService(ApiService.class);
            BaseRequest request = new BaseRequest();
            int userId = SPUtils.getInt(Constant.USER_ID, 0, context);
            request.put("userId", userId);
            String phone = SPUtils.getString(Constant.PHONE, "", context);
            request.put("phone", phone);
            request.put("yzm", yzm);
            request.put("loginPassword", loginPassword);
            service.modifyPhoneOne(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getCheckResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }


        public void modifyPhoneTwo(Context context, String yzm, String phone) {
            ApiService service = ServiceGenerator.createService(ApiService.class);
            BaseRequest request = new BaseRequest();
            int userId = SPUtils.getInt(Constant.USER_ID, 0, context);
            request.put("userId", userId);
            request.put("yzm", yzm);
            request.put("phone", phone);
            service.modifyPhoneTwo(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getModifyResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }

        public void modifyPhoneThree(String phone) {//发送验证码第二次
            ApiService service = ServiceGenerator.createService(ApiService.class);
            BaseRequest request = new BaseRequest();
            request.put("phone", phone);
            request.put("type", "6");
            service.modifyPhoneThree(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getYZMSecond(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }

    }


    public interface IModifyPhone extends IBaseView {
        void getYZM(Response<ResultDTO> response);//获取验证码，第一步

        void getCheckResult(Response<ResultDTO> response);//获取验证码，第一步

        void getYZMSecond(Response<ResultDTO> response);//获取验证码，第二步

        void getModifyResult(Response<ResultDTO> response);

    }
}
